package org.htmlparser.parserapplications.filterbuilder.wrappers;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JCheckBox;
import org.htmlparser.Node;
import org.htmlparser.NodeFilter;
import org.htmlparser.Parser;
import org.htmlparser.filters.HasParentFilter;
import org.htmlparser.parserapplications.filterbuilder.Filter;
import org.htmlparser.parserapplications.filterbuilder.SubFilterList;

public class HasParentFilterWrapper extends Filter
  implements ActionListener
{
  protected SubFilterList mContainer;
  protected HasParentFilter mFilter = new HasParentFilter();
  protected JCheckBox mRecursive = new JCheckBox("Recursive");

  public HasParentFilterWrapper()
  {
    add(this.mRecursive);
    this.mRecursive.addActionListener(this);
    this.mRecursive.setSelected(this.mFilter.getRecursive());
    this.mContainer = new SubFilterList(this, "Parent Filter", 1);
    add(this.mContainer);
  }

  public boolean accept(Node paramNode)
  {
    return this.mFilter.accept(paramNode);
  }

  public void actionPerformed(ActionEvent paramActionEvent)
  {
    if (paramActionEvent.getSource() == this.mRecursive)
    {
      boolean bool = this.mRecursive.isSelected();
      this.mFilter.setRecursive(bool);
    }
  }

  public String getDescription()
  {
    return "Has Parent";
  }

  public String getIconSpec()
  {
    return "images/HasParentFilter.gif";
  }

  public NodeFilter getNodeFilter()
  {
    HasParentFilter localHasParentFilter = new HasParentFilter();
    localHasParentFilter.setRecursive(this.mFilter.getRecursive());
    NodeFilter localNodeFilter = this.mFilter.getParentFilter();
    if (localNodeFilter != null)
      localHasParentFilter.setParentFilter(((Filter)localNodeFilter).getNodeFilter());
    return localHasParentFilter;
  }

  public NodeFilter[] getSubNodeFilters()
  {
    NodeFilter[] arrayOfNodeFilter;
    NodeFilter localNodeFilter = this.mFilter.getParentFilter();
    if (localNodeFilter != null)
    {
      arrayOfNodeFilter = new NodeFilter[1];
      arrayOfNodeFilter[0] = localNodeFilter;
    }
    while (true)
    {
      return arrayOfNodeFilter;
      arrayOfNodeFilter = new NodeFilter[0];
    }
  }

  public void setNodeFilter(NodeFilter paramNodeFilter, Parser paramParser)
  {
    this.mFilter = ((HasParentFilter)paramNodeFilter);
    this.mRecursive.setSelected(this.mFilter.getRecursive());
  }

  public void setSubNodeFilters(NodeFilter[] paramArrayOfNodeFilter)
  {
    if (paramArrayOfNodeFilter.length != 0)
      this.mFilter.setParentFilter(paramArrayOfNodeFilter[0]);
    while (true)
    {
      return;
      this.mFilter.setParentFilter(null);
    }
  }

  public String toJavaCode(StringBuffer paramStringBuffer, int[] paramArrayOfInt)
  {
    String str1;
    String str2;
    String str3;
    if (this.mFilter.getParentFilter() != null)
    {
      str1 = ((Filter)this.mFilter.getParentFilter()).toJavaCode(paramStringBuffer, paramArrayOfInt);
      StringBuffer localStringBuffer = new StringBuffer().append("filter");
      int i = paramArrayOfInt[1];
      paramArrayOfInt[1] = (i + 1);
      str2 = i;
      spaces(paramStringBuffer, paramArrayOfInt[0]);
      paramStringBuffer.append("HasParentFilter ");
      paramStringBuffer.append(str2);
      paramStringBuffer.append(" = new HasParentFilter ();");
      newline(paramStringBuffer);
      spaces(paramStringBuffer, paramArrayOfInt[0]);
      paramStringBuffer.append(str2);
      paramStringBuffer.append(".setRecursive (");
      if (!(this.mFilter.getRecursive()))
        break label199;
      str3 = "true";
    }
    while (true)
    {
      while (true)
      {
        paramStringBuffer.append(str3);
        paramStringBuffer.append(");");
        newline(paramStringBuffer);
        if (str1 != null)
        {
          spaces(paramStringBuffer, paramArrayOfInt[0]);
          paramStringBuffer.append(str2);
          paramStringBuffer.append(".setParentFilter (");
          paramStringBuffer.append(str1);
          paramStringBuffer.append(");");
          newline(paramStringBuffer);
        }
        return str2;
        str1 = null;
      }
      label199: str3 = "false";
    }
  }
}